package com.beerbear.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Beer Bear
 * @Description: RabbitMQ Fanout 广播模式的配置类
 * @Date: 2021/9/3 11:04
 */
@Configuration
public class FanoutConfig {

    /**
     * create by: Beer Bear
     * description: 声明一个交换机
     * create time: 2021/9/3 11:05
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout");
    }


    /**
     * create by: Beer Bear
     * description: 声明两个队列
     * create time: 2021/9/3 11:06
     */
    @Bean
    public Queue fanoutQueue1() {
        return new Queue("fanout.queue1");
    }

    @Bean
    public Queue fanoutQueue2() {
        return new Queue("fanout.queue2");
    }


    /**
     * create by: Beer Bear
     * description: 绑定队列与交换机
     * create time: 2021/9/3 11:08
     */
    @Bean
    public Binding bindingQueue1(Queue fanoutQueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding bindingQueue2(Queue fanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }
}
